#include "blockqueue.hpp"
#include <pthread.h>
#include <iostream>
#include <unistd.h>
void* consumer(void* arg)
{
  auto bq=((block_queue<int>*)arg);
  while(1)
  {
    sleep(1);
    int x=0;
    bq->pop(x);
    printf("consumer::%d\n",x);
  }
}

void* product(void* arg)
{
  auto bq=((block_queue<int>*)arg);
  while(1)
  {
    //sleep(1);
    int x=rand()%100+1;
    bq->push(x);
    printf("product::%d\n",x);
  }
}

int main()
{
  srand((unsigned int)time(nullptr));
  auto bq=new block_queue<int>(30);
  pthread_t c,p;
  pthread_create(&c,nullptr,consumer,(void*)bq);
  pthread_create(&p,nullptr,product,(void*)bq);


  pthread_join(c,nullptr);
  pthread_join(p,nullptr);
  return 0;
}
